package com.topboya.linker.diyview;

import android.app.Dialog;
import android.app.DialogFragment;
import android.content.Context;
import android.os.Bundle;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.topboya.linker.R;
import com.topboya.linker.ui.adapter.FlowdepTagAdapter;
import com.topboya.linker.utils.LogUtils;
import com.zhy.autolayout.AutoFrameLayout;
import com.zhy.view.flowlayout.TagAdapter;
import com.zhy.view.flowlayout.TagFlowLayout;

import java.security.acl.LastOwnerException;
import java.util.ArrayList;


/**
 * Created by aishua on 2017/2/17.
 */

public class SelectCustomerDialog extends DialogFragment {
    private static final String TAG = "SelectCustomerDialog:";
    private View.OnClickListener sure_listener;
    private View.OnClickListener cancle_listener;
    private TagFlowLayout.OnSelectListener select_listener;


    public void setOnSelectListener(TagFlowLayout.OnSelectListener listener) {

        this.select_listener = listener;
    }

    public static SelectCustomerDialog newInstance(ArrayList<String> msg) {

        SelectCustomerDialog dialog = new SelectCustomerDialog();
        Bundle args = new Bundle();
        args.putStringArrayList("msg", msg);
        dialog.setArguments(args);
        return dialog;
    }
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {

        ArrayList<String> msg = getArguments().getStringArrayList("msg");

        LayoutInflater inflaterDl = LayoutInflater.from(getActivity());
        LinearLayout layout = (LinearLayout) inflaterDl.inflate(R.layout.dialog_select_sustomer, null);

        //对话框
        final Dialog dialog = new Dialog(getActivity(),R.style.common_dialog_style);
        dialog.setContentView(layout);
        Window dialogWindow = dialog.getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        WindowManager manager= dialog.getWindow().getWindowManager();
        dialogWindow.setGravity(Gravity.CENTER);
//        lp.width = LinearLayout.LayoutParams.MATCH_PARENT; // 宽度
        lp.height =LinearLayout.LayoutParams.WRAP_CONTENT; // 高度
        Display defaultDisplay = manager.getDefaultDisplay();
        lp.width = (int) (defaultDisplay.getWidth() * 0.80);
        // 当Window的Attributes改变时系统会调用此函数,可以直接调用以应用上面对窗口参数的更改,也可以用setAttributes
        // dialog.onWindowAttributesChanged(lp);
        dialogWindow.setAttributes(lp);
        TagFlowLayout tagFlowLayout =  layout.findViewById(R.id.ll_select_cusomer);
        FlowdepTagAdapter flowdepTagAdapter = new FlowdepTagAdapter(getActivity(),tagFlowLayout,msg);
        tagFlowLayout.setAdapter(flowdepTagAdapter);
        if (select_listener !=null){

            tagFlowLayout.setOnSelectListener(select_listener);
        }
        return dialog;

    }



}
